package com.daou.smartpush.domain.license;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;

import com.daou.smartpush.domain.company.Company;
import com.daou.smartpush.model.license.LicenseModel;

@Entity
@Table(name = "license")
public class License implements Serializable {

    /**
	 * 
	 */
    private static final long serialVersionUID = 4948844356977717493L;

    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue
    private Long id;

    @Column(name = "hostId", nullable = false, unique = true)
    private String hostId;

    @Column(name = "unLimit", nullable = false)
    private String unLimit;

    @Column(name = "maxDeviceCnt", nullable = false)
    private int maxDeviceCnt;

    @Column(name = "expiredDate", nullable = false)
    private Date expiredDate;

    @Column(name = "pName", nullable = false)
    private String pName;

    @Column(name = "version", nullable = false)
    private String version;

    @Column(name = "created")
    private Date created;

    @Column(name = "modified")
    private Date modified;

    @ManyToOne
    @JoinColumn(name = "companySeq")
    private Company company;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getHostId() {
        return hostId;
    }

    public void setHostId(String hostId) {
        this.hostId = hostId;
    }

    public String getUnLimit() {
        return unLimit;
    }

    public void setUnLimit(String unLimit) {
        this.unLimit = unLimit;
    }

    public int getMaxDeviceCnt() {

        return maxDeviceCnt;
    }

    public void setMaxDeviceCnt(int maxDeviceCnt) {
        this.maxDeviceCnt = maxDeviceCnt;
    }

    public Date getExpiredDate() {
        return expiredDate;
    }

    public void setExpiredDate(Date expiredDate) {
        this.expiredDate = expiredDate;
    }

    public String getpName() {
        return pName;
    }

    public void setpName(String pName) {
        this.pName = pName;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getModified() {
        return modified;
    }

    public void setModified(Date modified) {
        this.modified = modified;
    }

    @PrePersist
    public void onPrePersist() {
        this.created = new Date();
        this.modified = this.created;
    }

    @PreUpdate
    public void onPreUpdate() {
        this.modified = new Date();
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public License() {
        super();
    }

    public License(LicenseModel licenseModel) {
        super();
        this.id = licenseModel.getId();
        this.hostId = licenseModel.getHostId();
        this.unLimit = licenseModel.getUnLimit();
        this.maxDeviceCnt = licenseModel.getMaxDeviceCnt();
        this.expiredDate = licenseModel.getExpiredDate();
        this.pName = licenseModel.getpName();
        this.version = licenseModel.getVersion();
    }

}
